package com.authine.cloudpivot.web.api.secondopen.service.impl;

import com.authine.cloudpivot.web.api.secondopen.dao.HOrgRoleMapper;
import com.authine.cloudpivot.web.api.secondopen.dao.HOrgRoleUserMapper;
import com.authine.cloudpivot.web.api.secondopen.dao.Iusi6HYGLMapper;
import com.authine.cloudpivot.web.api.secondopen.dao.PortalMapper;
import com.authine.cloudpivot.web.api.secondopen.modules.CompanyVO;
import com.authine.cloudpivot.web.api.secondopen.service.PortalService;
import com.authine.cloudpivot.web.api.secondopen.utils.CommUtil;
import com.authine.cloudpivot.web.api.secondopen.vo.*;
import com.authine.cloudpivot.web.api.utils.DateUtil;
import com.authine.cloudpivot.web.api.utils.StringUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * @Author: brookpeng
 * @Date: 2021/9/15 13:33
 */
@Service
public class PortalServiceImpl implements PortalService {
    private static final Logger log = LoggerFactory.getLogger(PortalServiceImpl.class);

    @Autowired
    private HOrgRoleUserMapper hOrgRoleUserMapper;
    @Autowired
    private HOrgRoleMapper hOrgRoleMapper;
    @Autowired
    private Iusi6HYGLMapper iusi6HYGLMapper;
    @Autowired
    private PortalMapper portalMapper;
    @Autowired
    private CommUtil commUtil;

    private String roleName = "集团管理人员";

    private static Pattern NUMBER_PATTERN = Pattern.compile("[0-9]");

    @Override
    public Map<String,List<MeetingInfoVO>> getMeetingRoomInfo(String userId, String date, String tableName, String sourceId, String tableName2, String companyId ,Boolean thismonth , Boolean thisweek ,String meetroom) {

        // 是否是“集团管理人员”
        boolean isOrganizationAdministrator = false;

        List<Map<String, Object>> meetingInfo = new ArrayList<>();

        // 获取“集团管理人员”角色的对应ID
        List<Map<String, Object>> targetRuleId = hOrgRoleMapper.getTargetRuleId(roleName);
        String roleId = "";
        // 获取集团管理人员（可以看到所有会议室信息的人员）
        if (CollectionUtils.isNotEmpty(targetRuleId) && targetRuleId.size() == 1) {
            roleId = (String) targetRuleId.get(0).get("roleId");
        }
        // 获取当前用户角色
        List<Map<String, Object>> userRole = hOrgRoleUserMapper.getUserRole(userId);
        if (CollectionUtils.isNotEmpty(userRole)) {
            for (Map<String, Object> stringObjectMap : userRole) {
                String theRoleId = (String) stringObjectMap.get("roleId");
                // 若用户持有“集团管理人员”角色则可查看所有会议室信息
                if (roleId.equals(theRoleId)) {
                    isOrganizationAdministrator = true;
                    break;
                }
            }
        }
        if (isOrganizationAdministrator && StringUtils.isEmpty(sourceId)) {
            meetingInfo = iusi6HYGLMapper.getMeetingInfoAll(date, tableName, thismonth, thisweek,companyId,meetroom);
        } else {
            // 获取当前用户所属公司（1#‘xxxxxx’）
            List<String> companys = new ArrayList<>();
            if (StringUtils.isNotEmpty(sourceId)) {
                companys.add(sourceId);
            } else {
                List<Map<String, Object>> company = portalMapper.getCompany(userId);
                for (Map<String, Object> stringObjectMap : company) {
                    String queryCode = (String)stringObjectMap.get("queryCode");
                    if (queryCode.length() > 2) {
                        int i = queryCode.indexOf("#");
                        // 寻找是否有第二次出现的位置
                        int j = queryCode.indexOf("#", i + 1);
                        String companySourceId;
                        if (j <= i) {
                            companySourceId = queryCode.substring(i);
                        } else {
                            companySourceId = queryCode.substring(i + 1, j);
                        }
                        companys.add(companySourceId);
                    } else {
                        log.info("*********用户{}直接挂载在主组织下，无法查询所属公司会议信息*********", userId);
                    }
                }
            }
            List<String> companysSelect = companys.stream().distinct().collect(Collectors.toList());
            meetingInfo = iusi6HYGLMapper.getMeetingInfoByQueryCode(date,thismonth,thisweek,companysSelect,meetroom);
        }
        // 返回数据准备
        //Map<String, MeetingRoomVO> result = new LinkedHashMap<>();
//        List<Map<String, Object>> meetingRooms = portalMapper.getMeetingRooms();
        //List<Map<String, Object>> meetingRooms = getMeetingRoomMethod(userId, tableName2, isOrganizationAdministrator, companyId);
//        for (Map<String, Object> meetingRoom : meetingRooms) {
//            String name = (String) meetingRoom.get("meetingRoomName");
//            result.put(name, new MeetingRoomVO());
//        }
        Map<String,List<MeetingInfoVO>> newresult = new LinkedHashMap<>();
        if (thisweek){
            List<String> weekByDate = DateUtil.getWeekByDate(date);
            for (String today: weekByDate) {
                newresult.put(today,null);
            }
        }
        if(thismonth){
            List<String> monthByDate = DateUtil.getMonthByDate(date);
            for (String today: monthByDate) {
                newresult.put(today,null);
            }
        }
        for (Map<String, Object> theInfo : meetingInfo) {
            //获取会议日期，根据日期进行分组
            // 开始时间
            String fromTimeTemp = (String) theInfo.get("fromTime");
            String fromTime = fromTimeTemp.substring(0, 10);
            if (newresult.containsKey(fromTime)){
                MeetingInfoVO meetingInfoVO = new MeetingInfoVO();
                //地点
                String place =(String) theInfo.get("meetingRoom");
                meetingInfoVO.setPlace(place);
                // 开始时间
                String fromTime1 = fromTimeTemp.substring(11, 16);
                meetingInfoVO.setTimeFrom(fromTime1);
                // 结束时间
                String toTimeTemp = (String) theInfo.get("toTime");
                String toTime = toTimeTemp.substring(11, 16);
                meetingInfoVO.setTimeTO(toTime);
                // 会议标题
                String meetingTitle = (String) theInfo.get("meetingTitle");
                meetingInfoVO.setMeetingTitle(meetingTitle);
                //时间区间
                meetingInfoVO.setShowTime(fromTime1+"~"+toTime);
                meetingInfoVO.setMeetingDate(fromTime);
                if (CollectionUtils.isEmpty(newresult.get(fromTime))){
                    List<MeetingInfoVO> mto=new ArrayList<>();
                    mto.add(meetingInfoVO);
                    newresult.put(fromTime,mto);
                }else{
                    List<MeetingInfoVO> meetingInfoVOS = newresult.get(fromTime);
                    meetingInfoVOS.add(meetingInfoVO);
                    newresult.put(fromTime,meetingInfoVOS);
                }
            }
        }
        return newresult;
    }

    private void setData(MeetingRoomVO meetingRoomVO, MeetingInfoVO meetingInfoVO, String fromTime) {
        switch (fromTime) {
            case "08:00":
                meetingRoomVO.setTime1(meetingInfoVO);
                break;
            case "08:30":
                meetingRoomVO.setTime2(meetingInfoVO);
                break;
            case "09:00":
                meetingRoomVO.setTime3(meetingInfoVO);
                break;
            case "09:30":
                meetingRoomVO.setTime4(meetingInfoVO);
                break;
            case "10:00":
                meetingRoomVO.setTime5(meetingInfoVO);
                break;
            case "10:30":
                meetingRoomVO.setTime6(meetingInfoVO);
                break;
            case "11:00":
                meetingRoomVO.setTime7(meetingInfoVO);
                break;
            case "11:30":
                meetingRoomVO.setTime8(meetingInfoVO);
                break;
            case "12:00":
                meetingRoomVO.setTime9(meetingInfoVO);
                break;
            case "12:30":
                meetingRoomVO.setTime10(meetingInfoVO);
                break;
            case "13:00":
                meetingRoomVO.setTime11(meetingInfoVO);
                break;
            case "13:30":
                meetingRoomVO.setTime12(meetingInfoVO);
                break;
            case "14:00":
                meetingRoomVO.setTime13(meetingInfoVO);
                break;
            case "14:30":
                meetingRoomVO.setTime14(meetingInfoVO);
                break;
            case "15:00":
                meetingRoomVO.setTime15(meetingInfoVO);
                break;
            case "15:30":
                meetingRoomVO.setTime16(meetingInfoVO);
                break;
            case "16:00":
                meetingRoomVO.setTime17(meetingInfoVO);
                break;
            case "16:30":
                meetingRoomVO.setTime18(meetingInfoVO);
                break;
            case "17:00":
                meetingRoomVO.setTime19(meetingInfoVO);
                break;
            case "17:30":
                meetingRoomVO.setTime20(meetingInfoVO);
                break;
            default:
                meetingRoomVO.setTimeOther(meetingInfoVO);
        }
    }

    @Override
    public List<String> getSelectedMeetingRoomSchedules(String meetingRoomName) {
        List<String> meetingRoomSchedules = new ArrayList<>();
        if (StringUtils.isEmpty(meetingRoomName)) {
            meetingRoomSchedules.add("会议室未选择");
            return meetingRoomSchedules;
        }
        List<Map<String, Object>> selectedMeetingRoomSchedules =
                iusi6HYGLMapper.getSelectedMeetingRoomSchedules(meetingRoomName);
        if (CollectionUtils.isNotEmpty(selectedMeetingRoomSchedules)) {
            // 整理当前选择会议室占用时间
            for (Map<String, Object> selectedMeetingRoomSchedule : selectedMeetingRoomSchedules) {
                Date fromTime = (Date)selectedMeetingRoomSchedule.get("fromTime");
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String fromTimeStr = sdf.format(fromTime);
                Date toTime = (Date)selectedMeetingRoomSchedule.get("toTime");
                String toTimeStr = sdf.format(toTime);
                String meetingTime = String.join("---", fromTimeStr, toTimeStr);
                meetingRoomSchedules.add(meetingTime);
            }
        } else {
            // 会议室未被占用
            meetingRoomSchedules.add("会议室未被占用");
        }
        return meetingRoomSchedules;
    }

    @Override
    public String checkMeetingTimes(String meetingRoomName, String startTime, String endTime) {
        String res = null;
        List<Map<String, Object>> selectedMeetingRoomSchedules =
                iusi6HYGLMapper.getSelectedMeetingRoomSchedules(meetingRoomName);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date startTimeDate = new Date();
        Date endTimeDate = new Date();
        try {
            startTimeDate = sdf.parse(startTime + ":00");
            endTimeDate = sdf.parse(endTime + ":00");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        for (int j = 0; j < selectedMeetingRoomSchedules.size(); j++) {
            Date J_S = (Date) selectedMeetingRoomSchedules.get(j).get("fromTime");
            Date J_E = (Date) selectedMeetingRoomSchedules.get(j).get("toTime");

            if ((J_S.compareTo(startTimeDate) == -1 && startTimeDate.compareTo(J_E) == -1)
                    || (J_S.compareTo(endTimeDate) == -1 && endTimeDate.compareTo(J_E) == -1)
                    || (startTimeDate.compareTo(J_S) == -1 && J_S.compareTo(endTimeDate) == -1)
                    || (startTimeDate.compareTo(J_E) == -1 && J_E.compareTo(endTimeDate) == -1)
//                    || J_E.compareTo(startTimeDate) == 0 || J_S.compareTo(endTimeDate) == 0
                    || J_E.compareTo(endTimeDate) == 0 || J_S.compareTo(startTimeDate) == 0) {
                res = sdf.format((Date) selectedMeetingRoomSchedules.get(j).get("fromTime")) + "---"
                        + sdf.format((Date) selectedMeetingRoomSchedules.get(j).get("toTime"));
                break;
            }
        }
        return res;
    }

    @Override
    public List<MeetingSchedulesVO> getUserMeetingSchedules(String userId, String tableName) {
        List<Map<String, Object>> meetingSchedulesByUserId = iusi6HYGLMapper.getMeetingSchedulesByUserId(userId);
        List<MeetingSchedulesVO> meetingSchedulesVOs = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(meetingSchedulesByUserId)) {
            for (Map<String, Object> stringObjectMap : meetingSchedulesByUserId) {
                MeetingSchedulesVO meetingSchedulesVO = new MeetingSchedulesVO();
                String fromTime = (String) stringObjectMap.get("fromTime");
                meetingSchedulesVO.setId((String) stringObjectMap.get("id"));
                meetingSchedulesVO.setCreater((String) stringObjectMap.get("createrName"));
                meetingSchedulesVO.setMeetingTitle((String) stringObjectMap.get("meetingTitle"));
                meetingSchedulesVO.setMeetingDetail((String) stringObjectMap.get("meetingDetail"));
                meetingSchedulesVO.setMeetingTime(fromTime.substring(0, 16));
                meetingSchedulesVO.setFromTime(fromTime);
                meetingSchedulesVO.setToTime((String) stringObjectMap.get("toTime"));
                meetingSchedulesVO.setMeetingRoom((String) stringObjectMap.get("meetingRoom"));
                meetingSchedulesVOs.add(meetingSchedulesVO);
            }
            return meetingSchedulesVOs;
        }
        return meetingSchedulesVOs;
    }

    @Override
    public List<FileTreeVO> getUserFileTreeService(String userId, String schemaCode) {
        List<FileTreeVO> treeVOs = new ArrayList<>();

        if (StringUtils.isEmpty(schemaCode)) {
            // 一级目录
            List<Map<String, Object>> attachmentListByUserId = portalMapper.getAttachmentListByUserId(userId);
            List<Map<String, Object>> attachmentLists = portalMapper.getAttachmentListByUserIdGroupBySchemaCode(userId);
            for (Map<String, Object> stringObjectMap : attachmentListByUserId) {
                FileTreeVO fileTreeVO = new FileTreeVO();
                fileTreeVO.setTitle("ATG-" + stringObjectMap.get("name"));
                fileTreeVO.setKey((String) stringObjectMap.get("code"));
                fileTreeVO.setChildren(new ArrayList<>());
                treeVOs.add(fileTreeVO);
            }
            for (FileTreeVO treeVO : treeVOs) {
                for (Map<String, Object> attachmentList : attachmentLists) {
                    String appCode = (String) attachmentList.get("appCode");
                    if (treeVO.getKey().equals(appCode)) {
                        FileTreeVO fileTreeVO1 = new FileTreeVO();
                        fileTreeVO1.setTitle((String) attachmentList.get("schemaName"));
                        fileTreeVO1.setKey((String) attachmentList.get("schemaCode"));
                        treeVO.getChildren().add(fileTreeVO1);
                    }
                }
            }
            return treeVOs;
        } else {
            // 二级目录
            List<FileTreeVO> fileTreeVOS = new ArrayList<>();
            List<Map<String, Object>> attachmentLists = portalMapper.getAttachmentListByUserIdGroupByInstanceId(userId, schemaCode);
            for (Map<String, Object> attachmentList : attachmentLists) {
                FileTreeVO fileTreeVO1 = new FileTreeVO();
                fileTreeVO1.setTitle((String) attachmentList.get("instanceName"));
                fileTreeVO1.setKey((String) attachmentList.get("instanceId"));
                fileTreeVOS.add(fileTreeVO1);
            }
            return fileTreeVOS;
        }
    }

    @Override
    public List<FileVO> getUserFileNameService(String userId, String instanceId) {
        List<FileVO> fileVOs = new ArrayList<>();
        List<Map<String, Object>> attachmentLists = portalMapper.getAttachmentListByUserIdAndInstanceId(userId, instanceId);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (Map<String, Object> attachmentList : attachmentLists) {
            FileVO fileVO = new FileVO();
            fileVO.setTitle((String) attachmentList.get("fileName"));
            fileVO.setRefId((String) attachmentList.get("refId"));
            fileVO.setCreater((String) attachmentList.get("createrName"));
            fileVO.setCreateTime(sdf.format((Date) attachmentList.get("createdTime")));
            fileVOs.add(fileVO);
        }
        return fileVOs;
    }

    @Override
    public List<FileVO> getUserFileNameLikeService(String userId, String fileName, String searchTimeFrom, String searchTimeTo, String type) {
        List<FileVO> fileVOs = new ArrayList<>();
        if (StringUtils.isEmpty(fileName)) {
            fileName = "";
        }
        if (StringUtils.isEmpty(searchTimeFrom)) {
            searchTimeFrom = "1000-01-01";
        } else {
            searchTimeFrom = searchTimeFrom + " 00:00:00";
        }
        if (StringUtils.isEmpty(searchTimeTo)) {
            searchTimeTo = "9999-12-31";
        } else {
            searchTimeTo = searchTimeTo + " 23:59:59";
        }
        List<Map<String, Object>> attachmentLists = new ArrayList<>();
        if ("2".equals(type)) {
            attachmentLists = portalMapper.getHYJYListByHYLXLike(userId, "%" + userId + "%", "%" + fileName + "%", searchTimeFrom, searchTimeTo);
        } else {
            attachmentLists = portalMapper.getAttachmentListByFileName(userId, "%" + fileName + "%", searchTimeFrom, searchTimeTo);
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if ("2".equals(type)) {
            for (Map<String, Object> attachmentList : attachmentLists) {
                FileVO fileVO = new FileVO();
                fileVO.setTitle((String) attachmentList.get("meetingTitle") + " 会议纪要:" + (String) attachmentList.get("name"));
                fileVO.setRefId((String) attachmentList.get("refId"));
                fileVO.setCreater((String) attachmentList.get("createrName"));
                fileVO.setCreateTime(sdf.format((Date) attachmentList.get("createdTime")));
                fileVOs.add(fileVO);
            }
        } else {
            for (Map<String, Object> attachmentList : attachmentLists) {
                FileVO fileVO = new FileVO();
                fileVO.setTitle((String) attachmentList.get("fileName"));
                fileVO.setRefId((String) attachmentList.get("refId"));
                fileVO.setCreater((String) attachmentList.get("createrName"));
                fileVO.setCreateTime(sdf.format((Date) attachmentList.get("createdTime")));
                fileVOs.add(fileVO);
            }
        }
        return fileVOs;
    }

    @Override
    public List<FileTreeVO> getHYJYTreeService(String userId) {
        List<FileTreeVO> treeVOs = new ArrayList<>();
        FileTreeVO fileTreeVO = new FileTreeVO();
        fileTreeVO.setTitle("ARN");
        fileTreeVO.setKey("arn");
        fileTreeVO.setChildren(new ArrayList<>());
        FileTreeVO fileTreeVO2 = new FileTreeVO();
        fileTreeVO2.setTitle("ATG-会议纪要");
        fileTreeVO2.setKey("atg-hyjy");
        fileTreeVO2.setChildren(new ArrayList<>());
        List<Map<String, Object>> hyjyList = portalMapper.getHYJYList(userId, "%" + userId + "%");
        for (Map<String, Object> stringObjectMap : hyjyList) {
            FileTreeVO fileTreeVO3 = new FileTreeVO();
            fileTreeVO3.setTitle((String) stringObjectMap.get("hylx"));
            fileTreeVO3.setKey((String) stringObjectMap.get("hylx"));
            fileTreeVO2.getChildren().add(fileTreeVO3);
        }
        fileTreeVO.getChildren().add(fileTreeVO2);
        treeVOs.add(fileTreeVO);
        return treeVOs;
    }

    @Override
    public List<FileVO> getHYJYNameService(String userId, String key) {
        List<FileVO> fileVOs = new ArrayList<>();
        List<Map<String, Object>> attachmentLists = portalMapper.getHYJYListByHYLX(userId, "%" + userId + "%", key);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (Map<String, Object> attachmentList : attachmentLists) {
            FileVO fileVO = new FileVO();
            fileVO.setTitle((String) attachmentList.get("meetingTitle") + " 会议纪要:" + (String) attachmentList.get("name"));
            fileVO.setRefId((String) attachmentList.get("refId"));
            fileVO.setCreater((String) attachmentList.get("createrName"));
            fileVO.setCreateTime(sdf.format((Date) attachmentList.get("createdTime")));
            fileVOs.add(fileVO);
        }
        return fileVOs;
    }

    @Override
    public List<MeetingRoomVO> getMeetingRoomsByLoginUserDepartments(String userId, String tableName, boolean isAdministrator) {
        List<Map<String, Object>> data = getMeetingRoomMethod(userId, tableName, isAdministrator, null);
        List<MeetingRoomVO> meetingRoomVOS = new ArrayList<>();
        String companyId = null;
        for (Map<String, Object> item : data) {
            MeetingRoomVO meetingRoomVO = new MeetingRoomVO();
            String bCompany = (String) item.get("belongToCompany");
            int index = bCompany.indexOf(":");
            String newCompanyId = bCompany.substring(index + 2, index + 2 + 32);
            String companyName = null;
            if (!newCompanyId.equals(companyId)) {
                Map<String, Object> deptNameById = iusi6HYGLMapper.getDeptNameById(newCompanyId);
                companyName = (String) deptNameById.get("name");
                companyId = newCompanyId;
            }
            meetingRoomVO.setMeetingRoom(item.get("meetingRoomName") + "(" + companyName + ")");
            meetingRoomVO.setMeetingRoomCompanyID(companyId);
            meetingRoomVOS.add(meetingRoomVO);
        }
        return meetingRoomVOS;
    }

    private List<Map<String, Object>> getMeetingRoomMethod(String userId, String tableName, boolean isAdministrator, String companyId) {

        //获取当前用户的所有上级部门,包括本身
        List<String> org = new ArrayList<>();
        if (StringUtils.isEmpty(companyId)) {
            org = commUtil.GetDpeptsByUserId(userId);
        } else {
            org.add(companyId);
            isAdministrator = false;
        }
        StringBuilder sql = new StringBuilder();
        sql.append("SELECT MR.`meetingRoomName` AS meetingRoomName, MR.`belongToCompany` AS belongToCompany FROM ");
        sql.append(tableName + " MR");
        sql.append(" WHERE MR.`id` IS NOT NULL ");
        boolean addOR = false;
        if (!isAdministrator) {
            sql.append("AND ( ");
            for (String department : org) {
                if (addOR) {
                    sql.append("OR MR.`belongToCompany` LIKE '%" + department + "%'");
                } else {
                    sql.append("MR.`belongToCompany` LIKE '%" + department + "%'");
                    addOR = true;
                }
            }
            sql.append(") ");
        }
        sql.append("ORDER BY MR.sort");
        return iusi6HYGLMapper.getData(sql.toString());
    }

    @Override
    public List<CompanyVO> getCompanyListByLoginUserRole(boolean isAdministrator, String userId) {

        List<CompanyVO> companyVOS = new ArrayList<>();

        // 获取主组织ID
        List<Map<String, Object>> mainOrganizationID = portalMapper.getMainOrganizationID();
        String mainID = (String) mainOrganizationID.get(0).get("id");

        // 获取所有分公司
        List<Map<String, Object>> companyByLoginUserRole = portalMapper.getCompanyByLoginUserRole(mainID);

        // 获取当前用户所属公司（1#‘xxxxxx’）
        List<Map<String, Object>> company = portalMapper.getCompany(userId);
        if (isAdministrator) {
            for (Map<String, Object> objectMap : companyByLoginUserRole) {
                CompanyVO companyVO = new CompanyVO();
                String companyName = (String) objectMap.get("name");
                String id = (String) objectMap.get("id");
                String sourceId = (String) objectMap.get("sourceId");
                companyVO.setCompanyId(id);
                companyVO.setCompanyName(companyName);
                companyVO.setSourceId(sourceId);
                companyVOS.add(companyVO);
            }
        } else {
            List<String> companys = new ArrayList<>();
            for (Map<String, Object> stringObjectMap : company) {
                String queryCode = (String)stringObjectMap.get("queryCode");
                // 直接挂载在集团下的人，关联的department的queryCode长度不大于2
                if (queryCode.length() > 2) {
                    int i = queryCode.indexOf("#");
                    // 寻找是否有第二次出现的位置
                    int j = queryCode.indexOf("#", i + 1);
                    String companySourceId;
                    if (j <= i) {
                        companySourceId = queryCode.substring(i);
                    } else {
                        companySourceId = queryCode.substring(i + 1, j);
                    }
                    companys.add(companySourceId);

                } else {
                    log.info("*********用户{}直接挂载在主组织下，无法查询所属公司会议信息*********", userId);
                }
            }
            List<String> companysSelect = companys.stream().distinct().collect(Collectors.toList());
            for (String comp : companysSelect) {
                CompanyVO companyVO = new CompanyVO();
                for (Map<String, Object> stringObjectMap : companyByLoginUserRole) {
                    String sourceId = (String) stringObjectMap.get("sourceId");
                    if (StringUtils.isEmpty(sourceId)) {
                        sourceId = (String) stringObjectMap.get("sortKey");
                    }
                    // 判断是否是当前用户所属公司
                    if (comp.equals(sourceId)) {
                        String companyName = (String) stringObjectMap.get("name");
                        String id = (String) stringObjectMap.get("id");
                        companyVO.setCompanyId(id);
                        companyVO.setCompanyName(companyName);
                        companyVO.setSourceId(sourceId);
                        companyVOS.add(companyVO);
                        break;
                    }
                }
            }
        }
        return companyVOS;
    }

    @Override
    public List<Map<String, Object>> getListMeetingRoomByCompanyId(String companyId) {
        return  portalMapper.getListMeetingRoomByCompanyId(companyId);
    }
}